/*
 * This file is part of p4nb.
 *
 * p4nb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * p4nb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with p4nb.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * ColorsPanel.java
 *
 * Created on 17.04.2009, 11:44:14
 */

package org.heresylabs.netbeans.p4.options;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;
import org.openide.util.NbBundle;

/**
 *
 * @author Aekold Helbrass <Helbrass@gmail.com>
 */
public class ColorsPanel extends javax.swing.JPanel implements ActionListener {

    /** Creates new form ColorsPanel */
    public ColorsPanel() {
        initComponents();
        colorAddButton.addActionListener(this);
        colorBaseButton.addActionListener(this);
        colorDeleteButton.addActionListener(this);
        colorEditButton.addActionListener(this);
        colorLocalButton.addActionListener(this);
        colorOutdatedButton.addActionListener(this);
        colorUnknownButton.addActionListener(this);

        Font font = new Font("Monospaced", Font.PLAIN, colorBaseButton.getFont().getSize());
        colorAddButton.setFont(font);
        colorBaseButton.setFont(font);
        colorDeleteButton.setFont(font);
        colorEditButton.setFont(font);
        colorLocalButton.setFont(font);
        colorOutdatedButton.setFont(font);
        colorUnknownButton.setFont(font);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        JLabel jLabel1 = new JLabel();
        JLabel jLabel2 = new JLabel();
        JLabel jLabel3 = new JLabel();
        JLabel jLabel4 = new JLabel();
        JLabel jLabel5 = new JLabel();
        JLabel jLabel6 = new JLabel();
        JLabel jLabel7 = new JLabel();

        colorBaseButton.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.colorBaseButton.text")); // NOI18N
        colorBaseButton.setContentAreaFilled(false);
        colorBaseButton.setOpaque(true);

        colorLocalButton.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.colorLocalButton.text")); // NOI18N
        colorLocalButton.setContentAreaFilled(false);
        colorLocalButton.setOpaque(true);

        colorUnknownButton.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.colorUnknownButton.text")); // NOI18N
        colorUnknownButton.setContentAreaFilled(false);
        colorUnknownButton.setOpaque(true);

        colorAddButton.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.colorAddButton.text")); // NOI18N
        colorAddButton.setContentAreaFilled(false);
        colorAddButton.setOpaque(true);

        colorDeleteButton.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.colorDeleteButton.text")); // NOI18N
        colorDeleteButton.setContentAreaFilled(false);
        colorDeleteButton.setOpaque(true);

        colorEditButton.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.colorEditButton.text")); // NOI18N
        colorEditButton.setContentAreaFilled(false);
        colorEditButton.setOpaque(true);

        colorOutdatedButton.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.colorOutdatedButton.text")); // NOI18N
        colorOutdatedButton.setContentAreaFilled(false);
        colorOutdatedButton.setOpaque(true);








        jLabel1.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.jLabel1.text")); // NOI18N
        jLabel2.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.jLabel2.text")); // NOI18N
        jLabel3.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.jLabel3.text")); // NOI18N
        jLabel4.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.jLabel4.text")); // NOI18N
        jLabel5.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.jLabel5.text")); // NOI18N
        jLabel6.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.jLabel6.text")); // NOI18N
        jLabel7.setText(NbBundle.getMessage(ColorsPanel.class, "ColorsPanel.jLabel7.text")); // NOI18N
        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(GroupLayout.LEADING)
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(LayoutStyle.RELATED, 29, Short.MAX_VALUE)
                        .add(colorBaseButton))
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(LayoutStyle.RELATED, 28, Short.MAX_VALUE)
                        .add(colorLocalButton))
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel3)
                        .addPreferredGap(LayoutStyle.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(colorUnknownButton))
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel4)
                        .addPreferredGap(LayoutStyle.RELATED, 37, Short.MAX_VALUE)
                        .add(colorAddButton))
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel5)
                        .addPreferredGap(LayoutStyle.RELATED, 22, Short.MAX_VALUE)
                        .add(colorDeleteButton))
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel6)
                        .addPreferredGap(LayoutStyle.RELATED, 37, Short.MAX_VALUE)
                        .add(colorEditButton))
                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel7)
                        .addPreferredGap(LayoutStyle.RELATED, 8, Short.MAX_VALUE)
                        .add(colorOutdatedButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(colorBaseButton)
                    .add(jLabel1))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(colorLocalButton)
                    .add(jLabel2))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(colorUnknownButton)
                    .add(jLabel3))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(colorAddButton)
                    .add(jLabel4))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(colorDeleteButton)
                    .add(jLabel5))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(colorEditButton)
                    .add(jLabel6))
                .addPreferredGap(LayoutStyle.RELATED)
                .add(layout.createParallelGroup(GroupLayout.BASELINE)
                    .add(colorOutdatedButton)
                    .add(jLabel7))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    final JButton colorAddButton = new JButton();
    final JButton colorBaseButton = new JButton();
    final JButton colorDeleteButton = new JButton();
    final JButton colorEditButton = new JButton();
    final JButton colorLocalButton = new JButton();
    final JButton colorOutdatedButton = new JButton();
    final JButton colorUnknownButton = new JButton();
    // End of variables declaration//GEN-END:variables

    private void colorChoosing(ActionEvent event) {
        JButton source = (JButton)event.getSource();
        Color c = JColorChooser.showDialog(this, "Choose Color", source.getBackground());
        if (c == null) {
            return;
        }
        source.setBackground(c);
        String r = Integer.toHexString(c.getRed());
        if (r.length() < 2) {
            r = '0' + r;
        }
        String g = Integer.toHexString(c.getGreen());
        if (g.length() < 2) {
            g = '0' + g;
        }
        String b = Integer.toHexString(c.getBlue());
        if (b.length() < 2) {
            b = '0' + b;
        }
        source.setText(r + g + b);
    }

    public void actionPerformed(ActionEvent e) {
        colorChoosing(e);
    }
}
